package com.yyt.module_main.act;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.vondear.rxtool.RxRegTool;
import com.yyt.libsrc.bean.SendCodeBean;
import com.yyt.libsrc.conf.Consts;
import com.yyt.libsrc.helper.MsgHelper;
import com.yyt.libsrc.net.JavaParamsBuilder;
import com.yyt.libsrc.net.NetUtil;
import com.yyt.libsrc.net.SuccessCallback;
import com.yyt.libsrc.router.RouteTable;
import com.yyt.module_main.R;
import com.yyt.module_main.databinding.ActivityRegisterBinding;
import com.yyt.module_main.vm.RegisterVM;

import top.lixb.libcommon.base.BaseActivity;
import top.lixb.libcommon.utils.CountDownUtil;

@Route(path = RouteTable.main_register)
public class RegisterActivity extends BaseActivity<ActivityRegisterBinding> {

    private CountDownUtil mCountDownUtil;
    private RegisterVM mVm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        mVm = new RegisterVM();
        mContentBinding.setVm(mVm);
        setTitle("注册");
        showToolbarDivider();
        setStatusbarBackgroundColor(getResources().getColor(R.color.color_status_bar));
        init();
    }

    private void init() {
        mCountDownUtil = new CountDownUtil(mContentBinding.tvGetSmscode)
                .setCountDownBackground(R.drawable.shape_sendsms_r5, R.drawable.shape_sendsms_r5_unenable)
                .setCountDownColor(R.color.color_sendsms_enable, R.color.color_sendsms_disable)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (!RxRegTool.isMobileSimple(mVm.account.get())) {
                            MsgHelper.showToast("手机号码不正确");
                            return;
                        }
                        NetUtil.sellerPost(new JavaParamsBuilder()
                                .addCmd(Consts.CMD.send_code)
                                .addP("phone",mVm.account.get())
                                .addP("code_type","1") //1：注册 2：登陆
                                .build(), new SuccessCallback<SendCodeBean>() {
                            @Override
                            public void onSuccess(SendCodeBean sendCodeBean) {
                                if (null != mCountDownUtil) {
                                    mCountDownUtil.start();
                                }
                            }
                        });
                    }
                });
    }
}
